// c++
#include <iostream>
#include <thread>

#include <static.hh>
#include <ostream.hh>

void func(int sleep_time, std::thread::id& my_tid, std::thread::id& init_tid)
{
    LOG_ENTER("func()");
    my_tid = std::this_thread::get_id();
    static const Mage::CtorSleep sleeper(sleep_time, my_tid);
    init_tid = sleeper.who();
    LOG_ENTER("func()");
}

int main()
{
    std::thread::id alpha_tid, beta_tid,
        alpha_init_tid, beta_init_tid;

    // create threads
    std::thread alpha(func, 4, std::ref(alpha_tid), std::ref(alpha_init_tid));
    std::thread beta(func, 0, std::ref(beta_tid), std::ref(beta_init_tid));

    // join threads
    alpha.join();
    beta.join();
    
    LOG_COUT_BEGIN << "Thread " << std::hex << std::showbase << alpha_tid
                   << " was init by thread " << alpha_init_tid << LOG_COUT_ENDL;
    LOG_COUT_BEGIN << "Thread " << std::hex << std::showbase << beta_tid
                   << " was init by thread " << beta_init_tid << LOG_COUT_ENDL;
}
